package personnel.department.pages.addpage;

import java.util.List;
import java.util.Set;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;

import personnel.department.dao.entity.Quit;
import personnel.department.pages.ModelProviderFactory;
import personnel.department.pages.PDTable;

public class QuitEditor extends AbstractTableEditor<Quit> {

	public QuitEditor(CTabFolder tabFolder) {
		super(tabFolder, "Уволен");
	}
	
	public QuitEditor(CTabFolder tabFolder, Set<Quit> quits) {
		super(tabFolder, "Уволен", quits);
	}
	
	@Override
	public PDTable<Quit> createTable(Composite parent) {
		return new PDTable<Quit>(parent) {
			
			@Override
			public List<Quit> setModelProvider() {
				return ModelProviderFactory.quitModel();
			}

			@Override
			protected void createColumns(Composite parent, TableViewer viewer) {
				String[] titles = { "Дата увольнения", "номер приказа", "Причина увольнения", "Основная работа",
						 "Внешнее совместительство", "Внутреннее совместительство"};
			    int[] bounds = { 130, 100, 130, 150, 170, 180};

			    TableViewerColumn col = createTableViewerColumn(getViewer(), titles[0], bounds[0], 0);
			    col.setLabelProvider(new ColumnLabelProvider() {
			      @Override
			      public String getText(Object element) {
			       Quit e = (Quit) element;
			        return format.format(e.getDateQuit());
			      }
			    });

			    col = createTableViewerColumn(getViewer(), titles[1], bounds[1], 1);
			    col.setLabelProvider(new ColumnLabelProvider() {
			      @Override
			      public String getText(Object element) {
				       Quit e = (Quit) element;
				        return String.valueOf(e.getNumberOrder());
			      }
			    });

			    col = createTableViewerColumn(getViewer(), titles[2], bounds[2], 2);
			    col.setLabelProvider(new ColumnLabelProvider() {
			      @Override
			      public String getText(Object element) {
				       Quit e = (Quit) element;
				        return e.getCauseOfQuit();
			      }
			    });
			    
			    col = createTableViewerColumn(getViewer(), titles[3], bounds[3], 3);
			    col.setLabelProvider(new ColumnLabelProvider() {
			    	@Override
			    	public String getText(Object element) {
					       Quit e = (Quit) element;
			    		return e.getWork().getBaseWork();
			    	}
			    });
			    
			    col = createTableViewerColumn(getViewer(), titles[4], bounds[4], 4);
			    col.setLabelProvider(new ColumnLabelProvider() {
			    	@Override
			    	public String getText(Object element) {
			    		Quit e = (Quit) element;
			    		return e.getWork().getExternalWork();
			    	}
			    });
			    
			    col = createTableViewerColumn(getViewer(), titles[5], bounds[5], 5);
			    col.setLabelProvider(new ColumnLabelProvider() {
			    	@Override
			    	public String getText(Object element) {
			    		Quit e = (Quit) element;
			    		return e.getWork().getInternalWork();
			    	}
			    });

			}
		};
	}

}
